home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / share / envy / instun / classes.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-03-04  |  26.5 KB  |  804 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. import sys
  5. import commands
  6. import string
  7. import os
  8. import popen2
  9. import fcntl
  10. import fcntl
  11. import select
  12. from os.path import isfile
  13. import shutil
  14. import fileinput
  15. import re
  16. import main
  17. import objects
  18. atimanlatest = '8.33.6'
  19. atimanlegacy = '8.28.8'
  20. nvmanlatest = '9746'
  21. nvmannewlegacy = '9631'
  22. nvmanlegacy = '7184'
  23.  
  24. class Compatibcheck:
  25.     
  26.     def check(self):
  27.         a = main.getCommandOutput('lspci | grep "VGA"')
  28.         b = a.lower().split(' ')
  29.         c = self.brandname.lower()
  30.         if c not in b:
  31.             print 'ENVY ERROR: ' + self.brandname + ' card not found'
  32.             event = 'error'
  33.         else:
  34.             event = 'passed'
  35.         return event
  36.  
  37.  
  38.  
  39. class Specsdetect:
  40.     
  41.     def init(self):
  42.         self.details = { }
  43.  
  44.     
  45.     def codename(self):
  46.         '''
  47.         Get system codename, can be warty/hoary/breezy/dapper/edgy/etch
  48.         '''
  49.         p = os.popen('lsb_release -c')
  50.         
  51.         try:
  52.             codename = p.readline().strip()
  53.             tokens = codename.split('\t')
  54.         finally:
  55.             p.close()
  56.  
  57.         self.details['osname'] = tokens[-1].lower()
  58.  
  59.     
  60.     def architecture(self):
  61.         '''
  62.         Detect whether the architecture is x86/ppc/amd64 
  63.         '''
  64.         arch = os.uname()[-1]
  65.         if arch in ('ppc', 'ppc64'):
  66.             arch = 'powerpc'
  67.         elif arch == 'x86_64':
  68.             arch = 'x86_64'
  69.         elif arch in ('i386', 'i686', 'i586', 'k7'):
  70.             arch = 'x86'
  71.         
  72.         self.details['arch'] = arch
  73.  
  74.     
  75.     def systemcheck(self):
  76.         if self.details['osname'] == 'dapper':
  77.             if self.details['arch'] == 'x86':
  78.                 print 'Ubuntu Dapper 32bit'
  79.             elif self.details['arch'] == 'x86_64':
  80.                 print 'Ubuntu Dapper 64bit'
  81.             else:
  82.                 print 'Your architecture is not supported by Envy'
  83.                 sys.exit()
  84.         elif self.details['osname'] == 'edgy':
  85.             if self.details['arch'] == 'x86':
  86.                 print 'Ubuntu Edgy 32bit'
  87.             elif self.details['arch'] == 'x86_64':
  88.                 print 'Ubuntu Edgy 64bit'
  89.             else:
  90.                 print 'ENVY ERROR: Your architecture is not supported by Envy'
  91.                 sys.exit()
  92.         elif self.details['osname'] == 'feisty':
  93.             if self.details['arch'] == 'x86':
  94.                 print 'Ubuntu Feisty 32bit'
  95.             elif self.details['arch'] == 'x86_64':
  96.                 print 'Ubuntu Feisty 64bit'
  97.             else:
  98.                 print 'ENVY ERROR: Your architecture is not supported by Envy'
  99.                 sys.exit()
  100.         else:
  101.             print 'ENVY ERROR: Your Operative System does not seem to be supported by Envy'
  102.             sys.exit()
  103.  
  104.     
  105.     def drivertype(self):
  106.         availabledrv = []
  107.         syscards = main.getCommandOutput('lspci -n | grep "0300" | cut -d " " -f3 | sed s/.*://').strip().lower()
  108.         systemcards = syscards.split('\n')
  109.         for element in systemcards:
  110.             
  111.             try:
  112.                 systemcards.remove('\n')
  113.             continue
  114.             except ValueError:
  115.                 continue
  116.             
  117.  
  118.         
  119.         for card in systemcards:
  120.             if self.cards.setdefault(card, 'N/A') != 'N/A':
  121.                 print 'Your graphic card has been detected as a ' + self.cards[card]
  122.                 print 'Your graphic card is supported by the latest driver'
  123.                 drvtype = 'latest'
  124.             elif self.middlecards.setdefault(card, 'N/A') != 'N/A':
  125.                 print 'Your graphic card has been detected as a ' + self.middlecards[card]
  126.                 print 'Your graphic card is supported by the new legacy driver'
  127.                 drvtype = 'middle'
  128.             elif self.legacycards.setdefault(card, 'N/A') != 'N/A':
  129.                 print 'Your graphic card has been detected as a ' + self.legacycards[card]
  130.                 print 'Your graphic card is supported by the legacy Driver'
  131.                 drvtype = 'oldest'
  132.             else:
  133.                 drvtype = 'unsupported'
  134.             availabledrv.append(drvtype)
  135.         
  136.         if 'latest' in availabledrv:
  137.             self.details['drvtype'] = 'latest'
  138.         elif 'middle' in availabledrv:
  139.             self.details['drvtype'] = 'middle'
  140.         elif 'oldest' in availabledrv:
  141.             self.details['drvtype'] = 'oldest'
  142.         else:
  143.             print "ENVY ERROR: Envy does not recognise your card as compatible with any version of the driver.                    this might happen because either your card is not supported by the driver or Envy's hardware                    detection failed. You can try the manual installation at your risk."
  144.             sys.exit()
  145.  
  146.     
  147.     def driverpushback(self):
  148.         availabledrv = []
  149.         systemcards = []
  150.         p = os.popen('lspci -n')
  151.         indentifier1 = re.compile('.*0300:.*:(.+) \\(.+\\)\n')
  152.         indentifier2 = re.compile('.*0300:.*:(.+)\n')
  153.         for line in p:
  154.             m1 = indentifier1.match(line)
  155.             m2 = indentifier2.match(line)
  156.             if m1:
  157.                 id = m1.group(1).strip().lower()
  158.                 systemcards.append(id)
  159.                 continue
  160.             if m2:
  161.                 id = m2.group(1).strip().lower()
  162.                 systemcards.append(id)
  163.                 continue
  164.         
  165.         for card in systemcards:
  166.             if self.cards.setdefault(card, 'N/A') != 'N/A':
  167.                 drvtype = 'latest'
  168.             elif self.middlecards.setdefault(card, 'N/A') != 'N/A':
  169.                 drvtype = 'middle'
  170.             elif self.legacycards.setdefault(card, 'N/A') != 'N/A':
  171.                 drvtype = 'oldest'
  172.             else:
  173.                 drvtype = 'unsupported'
  174.             availabledrv.append(drvtype)
  175.         
  176.         if 'latest' in availabledrv:
  177.             self.details['drvtype'] = 'latest'
  178.         elif 'middle' in availabledrv:
  179.             self.details['drvtype'] = 'middle'
  180.         elif 'oldest' in availabledrv:
  181.             self.details['drvtype'] = 'oldest'
  182.         
  183.  
  184.     
  185.     def atimanver(self):
  186.         while None:
  187.             drvchoice = raw_input('\n                Select the version of the driver which would you like to install:\n                1 - ' + atimanlatest + ' (latest)\n                2 - ' + atimanlegacy + ' (legacy)\n                3 - Back to main menu\n                (Type 1, 2 or 3)\n').strip()
  188.             if drvchoice == '1':
  189.                 self.details['drvtype'] = 'latest'
  190.                 self.details['manualchoice2'] = 'notmenu'
  191.                 break
  192.                 continue
  193.             if drvchoice == '2':
  194.                 self.details['drvtype'] = 'oldest'
  195.                 self.details['manualchoice2'] = 'notmenu'
  196.                 break
  197.                 continue
  198.             if drvchoice == '3':
  199.                 self.details['drvtype'] = 'oldest'
  200.                 self.details['manualchoice2'] = 'menu'
  201.                 break
  202.                 continue
  203.         if self.details['manualchoice2'] == 'menu':
  204.             objects.mainmenu()
  205.         else:
  206.             self.atireleasenum()
  207.  
  208.     
  209.     def nvidiamanver(self):
  210.         while None:
  211.             drvchoice = raw_input('\n                Select the version of the driver which would you like to install:\n                1 - ' + nvmanlatest + ' (latest)\n                2 - ' + nvmannewlegacy + ' (new legacy)\n                3 - ' + nvmanlegacy + ' (legacy)\n                4 - Back to main menu\n                (Type 1, 2, 3 or 4)\n').strip()
  212.             if drvchoice == '1':
  213.                 self.details['drvtype'] = 'latest'
  214.                 self.details['manualchoice1'] = 'notmenu'
  215.                 break
  216.                 continue
  217.             if drvchoice == '2':
  218.                 self.details['drvtype'] = 'middle'
  219.                 self.details['manualchoice1'] = 'notmenu'
  220.                 break
  221.                 continue
  222.             if drvchoice == '3':
  223.                 self.details['drvtype'] = 'oldest'
  224.                 self.details['manualchoice1'] = 'notmenu'
  225.                 break
  226.                 continue
  227.             if drvchoice == '4':
  228.                 self.details['manualchoice1'] = 'menu'
  229.                 break
  230.                 continue
  231.         if self.details['manualchoice1'] == 'menu':
  232.             objects.mainmenu()
  233.         else:
  234.             self.nvreleasenum()
  235.  
  236.     
  237.     def manualdetails(self):
  238.         while None:
  239.             drvchoice = raw_input('\n            Select the kind of driver which would you like to install:\n            1 - ATI\n            2 - NVIDIA\n            3 - Back to main menu\n            (Type either 1 or 2)\n').strip()
  240.             if drvchoice == '1':
  241.                 self.details['cardbrand'] = 'ati'
  242.                 self.details['manualchoice'] = 'notmenu'
  243.                 break
  244.                 continue
  245.             if drvchoice == '2':
  246.                 self.details['cardbrand'] = 'nvidia'
  247.                 self.details['manualchoice'] = 'notmenu'
  248.                 break
  249.                 continue
  250.             if drvchoice == '3':
  251.                 self.details['manualchoice'] = 'menu'
  252.                 break
  253.                 continue
  254.         if self.details['manualchoice'] == 'menu':
  255.             objects.mainmenu()
  256.         elif self.details['cardbrand'] == 'ati':
  257.             self.atimanver()
  258.         elif self.details['cardbrand'] == 'nvidia':
  259.             self.nvidiamanver()
  260.         
  261.  
  262.     
  263.     def nvreleasenum(self):
  264.         if self.details['drvtype'] == 'latest':
  265.             version = '1.0-' + nvmanlatest
  266.         elif self.details['drvtype'] == 'middle':
  267.             version = '1.0-' + nvmannewlegacy
  268.         elif self.details['drvtype'] == 'oldest':
  269.             version = '1.0-' + nvmanlegacy
  270.         
  271.         self.details['ver'] = version
  272.  
  273.     
  274.     def atireleasenum(self):
  275.         if self.details['drvtype'] == 'latest':
  276.             version = atimanlatest
  277.         elif self.details['drvtype'] == 'middle':
  278.             version = 'none'
  279.         elif self.details['drvtype'] == 'oldest':
  280.             version = atimanlegacy
  281.         
  282.         self.details['ver'] = version
  283.  
  284.     
  285.     def strippedver(self):
  286.         complete = self.details['ver']
  287.         stripped = complete.split('1.0-')
  288.         stripped.remove('')
  289.         self.details['strippedver'] = stripped[0]
  290.         next = int(stripped[0]) + 1
  291.         self.details['nextver'] = '1.0.' + str(next)
  292.  
  293.     
  294.     def changelog(self):
  295.         lines = []
  296.         file1 = '/usr/share/envy/nvidia-graphics-drivers/debian/changelog'
  297.         release = '1.0.' + self.details['strippedver']
  298.         opsystem = self.details['osname']
  299.         pat1 = re.compile('nvidia-graphics-drivers (\\(.+\\)) (.+); urgency=low')
  300.         text = open(file1, 'r')
  301.         optext = text.readlines()
  302.         for line in optext:
  303.             m1 = pat1.match(line)
  304.             if m1:
  305.                 line = 'nvidia-graphics-drivers (' + release + ') ' + opsystem + '; urgency=low\n'
  306.                 lines.append(line)
  307.                 continue
  308.             lines.append(line)
  309.         
  310.         text.close()
  311.         sep = ''
  312.         modtext = open(file1, 'w')
  313.         a = sep.join(lines)
  314.         modtext.write(a)
  315.         modtext.close()
  316.  
  317.     
  318.     def upstream(self):
  319.         lines = []
  320.         file1 = '/usr/share/envy/nvidia-graphics-drivers/debian/upstream_info'
  321.         release = self.details['strippedver']
  322.         next = self.details['nextver']
  323.         pat1 = re.compile('RELEASE=.+(.*)')
  324.         pat2 = re.compile('NEXTVER=.+(.*)')
  325.         text = open(file1, 'r')
  326.         optext = text.readlines()
  327.         for line in optext:
  328.             m1 = pat1.match(line)
  329.             m2 = pat2.match(line)
  330.             if m1:
  331.                 line = 'RELEASE=' + release + '\n'
  332.                 lines.append(line)
  333.                 continue
  334.             if m2:
  335.                 line = 'NEXTVER=' + next + '\n'
  336.                 lines.append(line)
  337.                 continue
  338.             lines.append(line)
  339.         
  340.         text.close()
  341.         sep = ''
  342.         modtext = open(file1, 'w')
  343.         a = sep.join(lines)
  344.         modtext.write(a)
  345.         modtext.close()
  346.  
  347.     
  348.     def nvidiapkgmake(self):
  349.         os.system('sudo chmod +x /usr/share/envy/nvidia-graphics-drivers/*.run')
  350.         os.system('cd /usr/share/envy/nvidia-graphics-drivers/ && sudo dpkg-buildpackage -b -uc')
  351.  
  352.     
  353.     def nvpkginstall(self):
  354.         drvname = self.details['drvname']
  355.         os.system('cd /usr/share/envy/ && sudo dpkg -i *.deb')
  356.         os.system('sudo apt-get install -f -y')
  357.  
  358.     
  359.     def nvrmdeb(self):
  360.         os.system('sudo rm /usr/src/nvidia-kernel*.deb')
  361.  
  362.     
  363.     def nvkmod(self):
  364.         os.system('sudo module-assistant prepare')
  365.         os.system('sudo module-assistant update')
  366.         os.system('sudo module-assistant build nvidia')
  367.         os.system('sudo module-assistant install nvidia')
  368.         os.system('sudo depmod -a')
  369.  
  370.     
  371.     def buildclean(self):
  372.         os.system('sudo rm /usr/share/envy/*.deb')
  373.         os.system('sudo rm /usr/share/envy/*.asc')
  374.         os.system('sudo rm /usr/share/envy/*.changes')
  375.         os.system('sudo rm /usr/share/envy/nvidia-graphics-drivers/*stamp')
  376.         os.system('sudo rm -R /usr/share/envy/nvidia-graphics-drivers/NVIDIA-Linux-' + self.details['arch'] + '-' + self.details['ver'] + '-' + self.details['pkg'])
  377.         os.system('sudo rm /usr/share/envy/nvidia-graphics-drivers/*.tar.gz')
  378.         os.system('sudo rm /usr/share/envy/nvidia-graphics-drivers/debian/files')
  379.         os.system('sudo rm /usr/share/envy/nvidia-graphics-drivers/debian/nvidia-glx.postinst.debhelper')
  380.         os.system('sudo rm /usr/share/envy/nvidia-graphics-drivers/debian/nvidia-glx.postrm.debhelper')
  381.         os.system('sudo rm /usr/share/envy/nvidia-graphics-drivers/debian/nvidia-glx.prerm.debhelper')
  382.         os.system('sudo rm /usr/share/envy/nvidia-graphics-drivers/debian/nvidia-glx.substvars')
  383.         os.system('sudo rm /usr/share/envy/nvidia-graphics-drivers/debian/nvidia-glx.substvars.bak')
  384.         os.system('sudo rm -R /usr/share/envy/nvidia-graphics-drivers/debian/nvidia-glx')
  385.         os.system('sudo rm -R /usr/share/envy/nvidia-graphics-drivers/debian/nvidia-glx-dev')
  386.         os.system('sudo rm -R /usr/share/envy/nvidia-graphics-drivers/debian/nvidia-kernel-source')
  387.         os.system('sudo rm -R /usr/share/envy/nvidia-graphics-drivers/debian/nvidia-glx-ia32')
  388.  
  389.     
  390.     def nvpkg(self):
  391.         if self.details['arch'] == 'x86':
  392.             pkg = 'pkg0'
  393.         elif self.details['arch'] == 'x86_64':
  394.             pkg = 'pkg2'
  395.         
  396.         self.details['pkg'] = pkg
  397.  
  398.     
  399.     def nvvarsum(self):
  400.         if self.details['arch'] == 'x86':
  401.             if self.details['drvtype'] == 'latest':
  402.                 md5old = '575f988468f2c34a302da3d21e282689'
  403.             elif self.details['drvtype'] == 'middle':
  404.                 md5old = 'b0d721c962c4df1a028ae18416d7e862'
  405.             else:
  406.                 md5old = '149e5e9934387da5da6ebe21d694e82a'
  407.         elif self.details['arch'] == 'x86_64':
  408.             if self.details['drvtype'] == 'latest':
  409.                 md5old = 'c0afc66e1c21a9a54ba6719b8edd3166'
  410.             elif self.details['drvtype'] == 'middle':
  411.                 md5old = '64b88c6f405e7f2dd1607c0062c0c1f3'
  412.             else:
  413.                 md5old = '332850387c4e7a4619753b856e3199e5'
  414.         
  415.         self.details['md5old'] = md5old
  416.  
  417.     
  418.     def ativarsum(self):
  419.         if self.details['arch'] == 'x86':
  420.             if self.details['drvtype'] == 'latest':
  421.                 md5old = '5fbd42d666d467a904acbaeb600c1d5a'
  422.             elif self.details['drvtype'] == 'middle':
  423.                 md5old = 'none'
  424.             else:
  425.                 md5old = '58189d7cc3625e399b1a434df893100f'
  426.         elif self.details['arch'] == 'x86_64':
  427.             if self.details['drvtype'] == 'latest':
  428.                 md5old = '5fbd42d666d467a904acbaeb600c1d5a'
  429.             elif self.details['drvtype'] == 'middle':
  430.                 md5old = 'none'
  431.             else:
  432.                 md5old = '58189d7cc3625e399b1a434df893100f'
  433.         
  434.         self.details['md5old'] = md5old
  435.  
  436.     
  437.     def nvpkgname(self):
  438.         driver = 'NVIDIA-Linux-' + self.details['arch'] + '-' + self.details['ver'] + '-' + self.details['pkg'] + '.run'
  439.         self.details['drvname'] = driver
  440.  
  441.     
  442.     def atipkgname(self):
  443.         if self.details['drvtype'] == 'oldest':
  444.             driver = 'ati-driver-installer-' + self.details['ver'] + '.run'
  445.         else:
  446.             driver = 'ati-driver-installer-' + self.details['ver'] + '-x86.x86_64.run'
  447.         self.details['drvname'] = driver
  448.  
  449.     
  450.     def nvftpfolder(self):
  451.         nvidiaftp = 'Linux-' + self.details['arch'] + '/' + self.details['ver']
  452.         self.details['nvftpdir'] = nvidiaftp
  453.  
  454.     
  455.     def nvaddress(self):
  456.         if self.details['drvtype'] == 'oldest':
  457.             wsite = ' http://download.nvidia.com/XFree86/'
  458.         else:
  459.             wsite = ' http://us.download.nvidia.com/XFree86/'
  460.         nvweb = wsite + self.details['nvftpdir'] + '/' + self.details['drvname']
  461.         self.details['website'] = nvweb
  462.  
  463.     
  464.     def atiaddress(self):
  465.         if self.details['drvtype'] == 'oldest' and self.details['arch'] == 'x86_64':
  466.             atiweb = ' https://a248.e.akamai.net/f/674/9206/0/www2.ati.com/drivers/linux/64bit/' + self.details['drvname']
  467.         else:
  468.             atiweb = ' https://a248.e.akamai.net/f/674/9206/0/www2.ati.com/drivers/linux/' + self.details['drvname']
  469.         self.details['website'] = atiweb
  470.  
  471.     
  472.     def getdriver(self):
  473.         if self.details['cardbrand'] == 'nvidia':
  474.             driverlocation = os.path.isfile('/usr/share/envy/nvidia-graphics-drivers/' + self.details['drvname'])
  475.         else:
  476.             driverlocation = os.path.isfile(self.details['drvname'])
  477.         if driverlocation:
  478.             print 'An installer has been detected'
  479.             if self.details['cardbrand'] == 'nvidia':
  480.                 md5new1 = main.getCommandOutput('md5sum /usr/share/envy/nvidia-graphics-drivers/' + self.details['drvname'] + ' | cut -d " " -f1')
  481.             else:
  482.                 md5new1 = main.getCommandOutput('md5sum ' + self.details['drvname'] + ' | cut -d " " -f1')
  483.             md5new = md5new1.strip()
  484.             print 'md5new: ' + md5new
  485.             print 'md5sumold: ' + self.details['md5old']
  486.             if md5new != self.details['md5old']:
  487.                 print 'ENVY ERROR: md5 Error! Trying to fetch the driver from the website'
  488.                 if self.details['cardbrand'] == 'nvidia':
  489.                     os.remove('/usr/share/envy/nvidia-graphics-drivers/' + self.details['drvname'])
  490.                 else:
  491.                     os.remove('/usr/share/envy/' + self.details['drvname'])
  492.                 self.getdriver()
  493.             
  494.         else:
  495.             print 'No installer detected'
  496.             print 'Download of the driver in progress, please wait'
  497.             if self.details['cardbrand'] == 'nvidia':
  498.                 os.system('cd /usr/share/envy/nvidia-graphics-drivers/ && sudo wget -c --tries=2 --timeout=20 --no-check-certificate' + self.details['website'])
  499.             else:
  500.                 os.system('sudo wget -c --tries=2 --timeout=20 --no-check-certificate' + self.details['website'])
  501.             if self.details['cardbrand'] == 'nvidia':
  502.                 md5new1 = main.getCommandOutput('md5sum /usr/share/envy/nvidia-graphics-drivers/' + self.details['drvname'] + ' | cut -d " " -f1')
  503.             else:
  504.                 md5new1 = main.getCommandOutput('md5sum ' + '/usr/share/envy/' + self.details['drvname'] + ' | cut -d " " -f1')
  505.             md5new = md5new1.strip()
  506.             print 'md5new: ' + md5new
  507.             print 'md5sumold: ' + self.details['md5old']
  508.             if md5new != self.details['md5old']:
  509.                 print 'ENVY ERROR: md5 Error! Operation aborted'
  510.                 sys.exit()
  511.             
  512.  
  513.     
  514.     def atipkgmake(self):
  515.         if self.details['osname'] != 'dapper':
  516.             os.system('sudo ln -sf /bin/bash /bin/sh')
  517.         
  518.         os.system('sh ' + self.details['drvname'] + ' --buildpkg Ubuntu/' + self.details['osname'])
  519.         if self.details['osname'] != 'dapper':
  520.             os.system('sudo ln -sf /bin/dash /bin/sh')
  521.         
  522.  
  523.     
  524.     def atipkginstall(self):
  525.         drvname = self.details['drvname']
  526.         os.system('sudo dpkg -i *.deb')
  527.  
  528.     
  529.     def atirmdeb(self):
  530.         os.system('sudo rm /usr/src/fglrx-kernel*.deb')
  531.  
  532.     
  533.     def atikmod(self):
  534.         os.system('sudo module-assistant prepare')
  535.         os.system('sudo module-assistant update')
  536.         os.system('sudo module-assistant build fglrx')
  537.         os.system('sudo module-assistant install fglrx')
  538.         os.system('sudo depmod -a')
  539.  
  540.     
  541.     def nvkernelcontrol(self):
  542.         a = os.uname()[2]
  543.         b = list(a)
  544.         c1 = a[0:6]
  545.         c = c1.strip()
  546.         kernels1 = [
  547.             '2.6.13',
  548.             '2.6.12',
  549.             '2.6.11',
  550.             '2.6.10']
  551.         kernels2 = [
  552.             '2.6.14',
  553.             '2.6.15',
  554.             '2.6.16',
  555.             '2.6.17',
  556.             '2.6.18',
  557.             '2.6.19',
  558.             '2.6.20']
  559.         systemname = self.details['osname']
  560.         if systemname == 'dapper':
  561.             if c in kernels1:
  562.                 os.system('sudo ln -sf /usr/bin/gcc-3.4 /usr/bin/gcc')
  563.             elif c in kernels2:
  564.                 os.system('sudo ln -sf /usr/bin/gcc-4.0 /usr/bin/gcc')
  565.             
  566.         
  567.         if systemname == 'edgy':
  568.             if c in kernels1:
  569.                 os.system('sudo ln -sf /usr/bin/gcc-3.4 /usr/bin/gcc')
  570.             elif c in kernels2:
  571.                 os.system('sudo ln -sf /usr/bin/gcc-4.1 /usr/bin/gcc')
  572.             
  573.         
  574.         d = '/usr/src/' + 'kernel-headers-' + a
  575.         f = '/usr/lib/xorg/modules'
  576.         g = '/usr/lib64/xorg/modules'
  577.         if os.path.isdir(d):
  578.             print 'Recompiled kernel detected'
  579.             z = d + '/arch/i386/'
  580.             if not os.path.isdir(z):
  581.                 os.system('sudo mkdir -p' + ' ' + z)
  582.             
  583.             if not os.path.isfile(z + 'Makefile.cpu'):
  584.                 if self.details['arch'] == 'x86_64':
  585.                     main.addmakefile64()
  586.                 else:
  587.                     main.addmakefile32()
  588.                 os.system('cd ' + d + ' && ' + 'sudo make prepare' + ' && ' + 'sudo make prepare scripts')
  589.                 if not os.path.isfile(z + 'Makefile.cpu'):
  590.                     print 'ENVY ERROR: Makefile.cpu not found!'
  591.                     sys.exit()
  592.                 
  593.             
  594.             if self.details['arch'] == 'x86_64':
  595.                 os.system('sudo sh ' + self.details['drvname'] + ' -n -s --x-prefix=' + g + ' --kernel-source-path=' + d)
  596.             else:
  597.                 os.system('sudo sh ' + self.details['drvname'] + ' -n -s --x-prefix=' + f + ' --kernel-source-path=' + d)
  598.         else:
  599.             e = '/usr/src/' + 'linux-headers-' + a
  600.             if self.details['arch'] == 'x86_64':
  601.                 os.system('sudo sh ' + self.details['drvname'] + ' -n -s --x-prefix=' + g + ' --kernel-source-path=' + e)
  602.             else:
  603.                 os.system('sudo sh ' + self.details['drvname'] + ' -n -s --x-prefix=' + f + ' --kernel-source-path=' + e)
  604.         os.system('sudo depmod -a')
  605.  
  606.     
  607.     def newkernelcontrol(self):
  608.         a = os.uname()[2]
  609.         b = list(a)
  610.         c1 = a[0:6]
  611.         c = c1.strip()
  612.         kernels1 = [
  613.             '2.6.13',
  614.             '2.6.12',
  615.             '2.6.11',
  616.             '2.6.10']
  617.         kernels2 = [
  618.             '2.6.14',
  619.             '2.6.15',
  620.             '2.6.16',
  621.             '2.6.17',
  622.             '2.6.18',
  623.             '2.6.19',
  624.             '2.6.20']
  625.         systemname = self.details['osname']
  626.         if systemname == 'dapper':
  627.             if c in kernels1:
  628.                 os.system('sudo ln -sf /usr/bin/gcc-3.4 /usr/bin/gcc')
  629.             elif c in kernels2:
  630.                 os.system('sudo ln -sf /usr/bin/gcc-4.0 /usr/bin/gcc')
  631.             
  632.         
  633.         if systemname == 'edgy':
  634.             if c in kernels1:
  635.                 os.system('sudo ln -sf /usr/bin/gcc-3.4 /usr/bin/gcc')
  636.             elif c in kernels2:
  637.                 os.system('sudo ln -sf /usr/bin/gcc-4.1 /usr/bin/gcc')
  638.             
  639.         
  640.         d = '/usr/src/' + 'kernel-headers-' + a
  641.         f = '/usr/lib/xorg/modules'
  642.         g = '/usr/lib64/xorg/modules'
  643.         if os.path.isdir(d):
  644.             print 'Recompiled kernel detected'
  645.             z = d + '/arch/i386/'
  646.             if not os.path.isdir(z):
  647.                 os.system('sudo mkdir -p' + ' ' + z)
  648.             
  649.             if not os.path.isfile(z + 'Makefile.cpu'):
  650.                 if self.details['arch'] == 'x86_64':
  651.                     main.addmakefile64()
  652.                 else:
  653.                     main.addmakefile32()
  654.                 os.system('cd ' + d + ' && ' + 'sudo make prepare' + ' && ' + 'sudo make prepare scripts')
  655.                 if not os.path.isfile(z + 'Makefile.cpu'):
  656.                     print 'ENVY ERROR: Makefile.cpu not found!'
  657.                     sys.exit()
  658.                 
  659.             
  660.         
  661.  
  662.     
  663.     def nvuninstalling(self):
  664.         os.system('cd /usr/share/envy/nvidia-graphics-drivers/ && sudo sh ' + self.details['drvname'] + ' --uninstall')
  665.         os.system('sudo aptitude reinstall linux-restricted-modules-`uname -r`')
  666.  
  667.     
  668.     def xorgbackup(self):
  669.         os.system('sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf_backup_`date +%Y%m%d%H%M`')
  670.  
  671.     
  672.     def restoregcc(self):
  673.         a = os.uname()[2]
  674.         b = list(a)
  675.         c1 = a[0:6]
  676.         c = c1.strip()
  677.         kernels1 = [
  678.             '2.6.13',
  679.             '2.6.12',
  680.             '2.6.11',
  681.             '2.6.10']
  682.         kernels2 = [
  683.             '2.6.14',
  684.             '2.6.15',
  685.             '2.6.16',
  686.             '2.6.17',
  687.             '2.6.18',
  688.             '2.6.19']
  689.         systemname = self.details['osname']
  690.         if systemname == 'dapper':
  691.             if c in kernels1:
  692.                 os.system('sudo ln -sf /usr/bin/gcc-3.4 /usr/bin/gcc')
  693.             elif c in kernels2:
  694.                 os.system('sudo ln -sf /usr/bin/gcc-4.0 /usr/bin/gcc')
  695.             
  696.         
  697.         if systemname == 'edgy':
  698.             if c in kernels1:
  699.                 os.system('sudo ln -sf /usr/bin/gcc-3.4 /usr/bin/gcc')
  700.             elif c in kernels2:
  701.                 os.system('sudo ln -sf /usr/bin/gcc-4.1 /usr/bin/gcc')
  702.             
  703.         
  704.  
  705.     
  706.     def nvxorgset(self):
  707.         distrolst = [
  708.             'edgy',
  709.             'etch',
  710.             'feisty']
  711.         systemname = self.details['osname']
  712.         if systemname in distrolst:
  713.             if self.details['drvtype'] == 'latest':
  714.                 os.system('sudo /usr/bin/nvidia-xconfig --composite')
  715.             else:
  716.                 os.system('sudo /usr/share/envy/legacy/nvidia-xconfig --no-composite')
  717.         else:
  718.             os.system('sudo /usr/bin/nvidia-xconfig')
  719.  
  720.     
  721.     def atixorgset(self):
  722.         distrolst = [
  723.             'edgy',
  724.             'etch',
  725.             'feisty']
  726.         systemname = self.details['osname']
  727.         objects.disablecomposite()
  728.         os.system('sudo aticonfig --initial')
  729.         os.system('sudo aticonfig --overlay-type=Xv')
  730.  
  731.  
  732.  
  733. class Composite:
  734.     
  735.     def operate(self):
  736.         lines = []
  737.         pat1 = re.compile('.*Section.*"Extensions".*\n')
  738.         pat2 = re.compile('.*Option.*"Composite".*"(.+)".*\n')
  739.         text = open(self.file, 'r')
  740.         optext = text.readlines()
  741.         for line in optext:
  742.             m1 = pat1.match(line)
  743.             m2 = pat2.match(line)
  744.             if m1:
  745.                 line = ''
  746.                 lines.append(line)
  747.                 continue
  748.             if m2:
  749.                 line = '>'
  750.                 lines.append(line)
  751.                 continue
  752.             lines.append(line)
  753.         
  754.         text.close()
  755.         sep = ''
  756.         modtext = open(self.file, 'w')
  757.         a = sep.join(lines)
  758.         modtext.write(a)
  759.         modtext.close()
  760.         lastlines = []
  761.         lasttext = open(self.file, 'r')
  762.         newtext = lasttext.readlines()
  763.         pat3 = re.compile('>.*EndSection.*\n')
  764.         for lastline in newtext:
  765.             m3 = pat3.match(lastline)
  766.             if m3:
  767.                 lastline = ''
  768.                 lastlines.append(lastline)
  769.                 continue
  770.             lastlines.append(lastline)
  771.         
  772.         lasttext.close()
  773.         modtext1 = open(self.file, 'w')
  774.         b = sep.join(lastlines)
  775.         modtext1.write(b)
  776.         modtext1.close()
  777.  
  778.  
  779.  
  780. class Compositechoice:
  781.     
  782.     def choosecomposite(self):
  783.         objects.removecomposite()
  784.         file = open(self.file, 'a')
  785.         option = '\nSection "Extensions"\n\tOption "Composite" "' + self.operation + '"\nEndSection\n\n'
  786.         file.write(option)
  787.         file.close()
  788.  
  789.  
  790.  
  791. class Chooselist:
  792.     
  793.     def init(self):
  794.         self.driver = 'none'
  795.  
  796.     
  797.     def blacklist(self):
  798.         '''restore Ubuntu original linux-restricted-modules-common'''
  799.         restrictedblk = open('/etc/default/linux-restricted-modules-common', 'w')
  800.         restrictedblk.write('# This file is sourced from the linux-restricted-modules-common init\n    # script and is used to disable the link-on-boot feature, one module\n    # at a time.  This can be useful if you want to use hand-compiled\n    # versions of one or more modules, but keep linux-restricted-modules\n    # installed on your system, or just to disable modules you don\'t use\n    # and speed up your boot process by a second or two.\n    #\n    # Use a space-separated list of modules you wish to not have linked\n    # on boot.  The following example shows a (condensed) list of all\n    # modules shipped in the linux-restricted-modules packages:\n    #\n    # DISABLED_MODULES="ath_hal fc fglrx ltm nv"\n    #\n    # Note that disabling "fc" disables all fcdsl drivers, "ltm" disables\n    # ltmodem and ltserial, and "nv" disables both the nvidia drivers.\n    # You can also name each module individually, if you prefer a subset.\n    \n    DISABLED_MODULES="' + self.driver + '"\n')
  801.         restrictedblk.close()
  802.  
  803.  
  804.